﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddPigPen.aspx.cs" Inherits="OnlineManagement.Web.pages.AddPigPen" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../resources/scripts/jquery-1.10.2.js" type="text/javascript"></script>
    <script src="../resources/scripts/myAjax.js" type="text/javascript"></script>
    <script src="../resources/scripts/jquery.cookie.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
        $(document).ready(function () {

            $("#txtId").blur(function () {
                $("#idpan").attr("class", "").html("");
                var value = $(this).val();
                //var hogger = $("#<%=hfHogger.ClientID %>").val();
                var hogger = $.cookie("hoggeryId");
                if (value == '') {
                    $("#idpan").addClass("input-notification attention png_bg").html('编号不能为空，请填写编号。');
                } else {
                    $.ajax2({
                        type: "post",
                        contentType: "application/json",
                        url: "../WebServices/PigPen.asmx/ExistPigPend",
                        dataType: "json",
                        data: "{ customerId:'" + value + "',hoggerIdStr:'" + hogger + "' }",
                        success: function (data) {
                            if (data.d.Flag) {
                                $("#idpan").addClass("input-notification success png_bg");
                            } else {
                                $("#idpan").addClass("input-notification attention png_bg").html(data.d.Message);
                            }
                        },
                        error: function (error) {
                            $("#idpan").addClass("input-notification error png_bg").html("服务器发生错误了，请稍后再试.");
                        }
                    });
                }
            });

            $("#btnSubmit").click(function () {
                var id = $("#txtId").val();
                var hogger = $("#<%=hfHogger.ClientID %>").val();
                var maxCapacity = $("#txtMaxCapacity").val();
                var desc = $("#textDesc").val();
                $.ajax2({
                    type: "post",
                    contentType: "application/json",
                    url: "../WebServices/PigPen.asmx/AddPigPen",
                    dataType: "json",
                    data: "{ hoggerId:'" + hogger + "',pigPenId:'" + id + "',maxCapacity:'" + maxCapacity + "',description:'" + desc + "' }",
                    success: function (data) {
                        alert(data.d.Message);
                    },
                    error: function (error) {
                        alert(data.d.Message);
                    }
                });

                return false;
            });
        });
    </script>
</head>
<body>
    <div>
     <form id="form1" runat="server">
      <h3>添加</h3>
        <p>
            <label>
               猪舍编号</label>
           <input type="text" id="txtId" onkeyup="JavaScript:this.value=this.value.replace(/\D/gi,'')" /> 
           <span id="idpan"></span>
        </p>
        <p>
            <label>最大容量</label>
            <input type="text" id="txtMaxCapacity" onkeyup="JavaScript:this.value=this.value.replace(/\D/gi,'')" value="0" />
        </p>
        <p>
            <label>猪舍描述</label>
            <textarea id="textDesc"  cols="20" rows="4"></textarea>
        </p>
        <p>
            <input type="submit" id="btnSubmit" value="提交" />
           
        </p>
        <p>
            <div id="msg"></div>
        </p>
        <asp:HiddenField runat="server" ID="hfHogger" />
    </form>
    </div>
</body>
</html>
